<?php

use mdm\admin\components\MenuHelper;

$callback = function ($menu) {
    $data = json_decode($menu['data'], true);
    $items = $menu['children'];
    $return = [
        'label' => $menu['name'],
        'url' => [$menu['route']],
    ];
    //自定义配置
    if ($data) {
        //visible
        isset($data['visible']) && $return['visible'] = $data['visible'];
        //icon
        isset($data['icon']) && $data['icon'] && $return['icon'] = $data['icon'];
        //other attribute e.g. class...
        $return['options'] = $data;
    }
    //没配置图标的显示默认图标
    (!isset($return['icon']) || !$return['icon']) && $return['icon'] = 'circle-o';
    $items && $return['items'] = $items;
    return $return;
};

echo '<aside class="main-sidebar">
    <section class="sidebar">';
//这里我们对一开始写的菜单menu进行了优化
echo \backend\components\Menu::widget([
    'options' => ['class' => 'sidebar-menu tree', 'data-widget' => 'tree'],
    'items' => MenuHelper::getAssignedMenu(Yii::$app->user->id, null, $callback, true),
]);
echo '</section></aside>';
?>